//===---- StaticGCPass.cpp - Put GC information in functions compiled --------//
//===----------------------- with llvm-gcc --------------------------------===//
//
//                     The VMKit project
//
// This file is distributed under the University of Illinois Open Source 
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//


#include "llvm/Module.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"

#include <cstdio>

#include "RCompilerCommon.h"

#include "bc.h"

using namespace llvm;

namespace R {

  class RIntrinsics : public ModulePass {
  public:
    static char ID;
    
    RIntrinsics() : ModulePass(ID) {}

    virtual bool runOnModule(Module& M);

    /// getAnalysisUsage - We do not modify anything.
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    } 

  };

  char RIntrinsics::ID = 0;
  RegisterPass<RIntrinsics> X("RIntrinsics",
															"Convert C function into R intrinsics");

	bool RIntrinsics::runOnModule(Module& M) {
		RCompilerCommon* comp = new RCompilerCommon(&M);

		for(int i=0; i<BC_LAST; i++)
			comp->evalFunctions[i]->addFnAttr(llvm::Attribute::AlwaysInline);

		return 1;
	}

}
